﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOABLL;
using TarreOA.TarreOAModels;

public partial class UserTalkHouse_Index : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            this.DataList_DataTable();
            if (this.DataList1.DataSource == null)
            {
                ScriptManager.RegisterClientScriptBlock(Page, GetType(), "", "alert('暂无开放的聊天室！');", true);
            }
        }
    }

    public void DataList_DataTable()
    {
        TalkHouseListService thlService = new TalkHouseListService();
        DataTable dt = new DataTable();
        dt.Columns.Add("TalkHouseId", typeof(string));
        dt.Columns.Add("TalkHouseName", typeof(string));
        dt.Columns.Add("TalkHouseOpenState", typeof(string));
        List<TalkHouseList> list = thlService.findALL();
        if (list != null && list.Count > 0)
        {
            foreach (TalkHouseList thl in list)
            {
                DataRow dr = dt.NewRow();
                dr["TalkHouseId"] = thl.TalkHouseId.ToString();
                dr["TalkHouseName"] = thl.TalkHouseName;
                dr["TalkHouseOpenState"] = thl.TalkHouseOpenState.ToString();
                dt.Rows.Add(dr);
            }
        }
        if (dt.Rows.Count > 0)
        {
            this.DataList1.DataSource = dt.DefaultView;
        }
        else
        {
            this.DataList1.DataSource = null;
        }
        this.DataList1.DataBind();
    }
    protected void DataList1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            string state = ((HtmlInputHidden)e.Item.FindControl("HidState")).Value;
            if (state.Equals("1"))
            {
                ((Label)e.Item.FindControl("LblState")).Visible = true;
                ((LinkButton)e.Item.FindControl("LbtIn")).Visible = false;
            }
        }
    }
    protected void LbtIn_Click(object sender, EventArgs e)
    {
        string thl_Id = ((LinkButton)sender).Attributes["thl_Id"];
        Response.Redirect("InTalk.aspx?thl_Id=" + thl_Id);
    }
}
